var a = getApp();

Page({
    data: {
        details: {},
        tabsIndex: 0,
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        love_name: "爱心值",
        receiveBtnLoading: !1
    },
    onLoad: function(a) {
        a.love_name & "" != a.love_name && this.setData({
            love_name: a.love_name
        }), wx.setNavigationBarTitle({
            title: a.love_name + "周期释放"
        }), this.getData(), this.getListData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    getData: function() {
        var t = this, e = a.getNetAddresss("plugin.love-cycle-award.frontend.controllers.cycle-award.statistics");
        a._getNetWork({
            url: e,
            success: function(e) {
                var s = e.data;
                if (1 != s.result) return a.tips(s.msg);
                t.setData({
                    details: s.data
                });
            }
        });
    },
    getListData: function() {
        var t = this;
        this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0;
        var e = a.getNetAddresss("plugin.love-cycle-award.frontend.controllers.cycle-award.queue-list"), s = {};
        this.data.tabsIndex > 0 && (s.status = this.data.tabsIndex), a._getNetWork({
            url: e,
            data: s,
            success: function(e) {
                var s = e.data;
                if (1 != s.result) return a.tips(s.msg);
                t.setData({
                    isLoadMore: !0,
                    total_page: s.data.last_page,
                    listData: s.data.reward_queues
                }), t.data.total_page || (t.data.total_page = 0);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page++;
            var e = {
                page: this.data.page
            };
            this.data.tabsIndex > 0 && (e.status = this.data.tabsIndex);
            var s = a.getNetAddresss("plugin.love-cycle-award.frontend.controllers.cycle-award.queue-list");
            a._getNetWork({
                url: s,
                data: e,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.data.isLoadMore = !0;
                        var s = e.data.reward_queues;
                        t.setData({
                            listData: t.data.listData.concat(s)
                        });
                    } else t.data.isLoadMore = !1, t.data.page--;
                }
            });
        }
    },
    gotoLoveCashbackRecord: function(a) {
        var t = a.currentTarget.dataset.id || a.target.dataset.id;
        wx.navigateTo({
            url: "/packageB/member/love/loveCashbackRecord/loveCashbackRecord?id=" + t
        });
    },
    receiveAwardGain: function() {
        var t = this;
        if (0 != this.data.details.receivable && 1 != this.data.receiveBtnLoading) {
            this.data.receiveBtnLoading = !0;
            var e = a.getNetAddresss("plugin.love-cycle-award.frontend.controllers.receive-award.gain");
            a._getNetWork({
                url: e,
                success: function(e) {
                    var s = e.data;
                    a.tips(s.msg), 1 == s.result && t.setData({
                        "details.receivable": 0
                    });
                },
                fail: function(a) {
                    console.log(a);
                },
                complete: function() {
                    t.data.receiveBtnLoading = !1;
                }
            });
        }
    },
    changeTabsIndex: function(a) {
        console.log(a), this.data.tabsIndex = a.detail.index, this.getListData();
    }
});